﻿using Axis.BusinessObject.Research;
using Axis.Dao.Research;
using Axis.Web.Administrator.Global;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Xml;

namespace Axis.Web.Views.Project
{
    public partial class ucProjectTop3 : System.Web.UI.UserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
                GetProjectList();
        }
        public void GetProjectList()
        {
            XmlDocument doc = new XmlDocument();
            XmlElement root = doc.CreateElement("InputValue");
            doc.AppendChild(root);
            //root.SetAttribute("UserID", CSecurity.MEMBER_ID.ToString());
            //root.SetAttribute("MemberID", CSecurity.MEMBER_ID.ToString());
            //root.SetAttribute("SecrectToken", CSecurity.SECRECT_TOKEN.ToString());
            root.SetAttribute("Context", "AvailableProject");
            root.SetAttribute("PageIndex", "1");
            root.SetAttribute("Type", "1");
            root.SetAttribute("RowsPerPage", "3");
            string inputValue = root.OuterXml;
            CResearchDao cResearchDao = new CResearchDao();
            IList<CProject> list = cResearchDao.GetProject(inputValue);
            string Top3 = "\n var Top3=[";
            if (list != null && list.Count > 0)
            {

                foreach (CProject project in list)
                {
                    int index = list.IndexOf(project);//ResearchDetail.aspx
                    string projectTitle = string.Format("<a href='../../Views/Research/ResearchList.aspx?ID={0}'>{1}</a>", project.ID, project.Name);
                    switch (index)
                    {
                        case 0:
                            ltrProjectDesc1.Text = project.Summary;
                            ltrProjectTitle1.Text = projectTitle;
                            imgProjectImage1.ImageUrl = project.Image1;
                            imgProjectImage1.Attributes["ProjectID"] = project.ID.ToString();
                            Top3 += project.ID.ToString() + ",";
                            break;
                        case 1:
                            ltrProjectDesc2.Text = project.Summary;
                            ltrProjectTitle2.Text = projectTitle;
                            imgProjectImage2.ImageUrl = project.Image1;
                            imgProjectImage2.Attributes["ProjectID"] = project.ID.ToString();
                            Top3 += project.ID.ToString() + ",";
                            break;
                        case 2:
                            ltrProjectDesc3.Text = project.Summary;
                            ltrProjectTitle3.Text = projectTitle;
                            imgProjectImage3.ImageUrl = project.Image1;
                            imgProjectImage3.Attributes["ProjectID"] = project.ID.ToString();
                            Top3 += project.ID.ToString();
                            break;
                        default:
                            break;
                    }
                }
            }
            Top3 += "];\n";
            Page.ClientScript.RegisterClientScriptBlock(Page.GetType(), "Top3",
                                 Top3, true);
        }

    }
}